package com.runfast.waimai.task;

import com.runfast.waimai.dao.model.RunfastGoodsSellRecord;
import com.runfast.waimai.dao.model.WaiMaiRunfastShopper;
import com.runfast.waimai.service.RunfastGoodsSellRecordService;
import com.runfast.waimai.service.WaiMaiRunfastShopperService;
import com.runfast.waimai.utils.websocket.DiaoDuWebsocketController;
//import com.runfast.waimai.utils.websocket.WebsocketController;
import com.runfast.waimai.web.controller.goods.GoodsSellController;
import com.runfast.waimai.web.controller.shopper.ShopperController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * ${DESCRIPTION}  定时任务
 *
 * @author chenzheng
 * @create 2018-05-15 16:05
 **/
@Component
public class ExampleTimer {
    @Autowired
    private GoodsSellController goodsSellController;
    @Autowired
    private WaiMaiRunfastShopperService waiMaiRunfastShopperService;
    @Autowired
    private ShopperController shopperController;
    @Autowired
    private DiaoDuWebsocketController diaoDuWebsocketController;
    @Autowired
    private RunfastGoodsSellRecordService runfastGoodsSellRecordService;
    //@Autowired
    //private WebsocketController websocketController;

    SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    /*@Scheduled(fixedRate = 10000)
    public void timerRate() {
        System.out.println(dateFormat.format(new Date()));
    }

    //第一次延迟1秒执行，当执行完后2秒再执行
    @Scheduled(initialDelay = 1000, fixedDelay = 2000)
    public void timerInit() {
        System.out.println("init : "+dateFormat.format(new Date()));
    }*/
    /**把标记为置满的商品数量更新为10000*/
    //每天零点执行
    @Scheduled(cron = "0 0 0 * * ?")
    public void timerCron() {
        goodsSellController.setNumFull();
        System.out.println("current time : "+ dateFormat.format(new Date()));
    }


     double lat=30.594967;
     double lon=114.35845699999999;
    //    每分钟启动
    //@Scheduled(cron = "0 0/1 * * * ?")
    /*@Scheduled(fixedDelay = 5000)
    public void timerToNow(){
        WaiMaiRunfastShopper shopper=waiMaiRunfastShopperService.selectByPrimaryKey(1164);
        lat=lat+0.000001;
        lon=lon+0.00000000000001;
        shopper.setLatitude( String.valueOf  (lat));
        shopper.setLongitude( String.valueOf  (lon));
        List<WaiMaiRunfastShopper> list=new ArrayList<WaiMaiRunfastShopper>();
        list.add(shopper);
        shopperController.setList(list);
        diaoDuWebsocketController.broadcast(null,list.get(0));
        //System.out.println("now time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    @Scheduled(fixedDelay = 8000)
    public void timerToNow1(){
        RunfastGoodsSellRecord goodsSellRecord1=runfastGoodsSellRecordService.selectByPrimaryKey(528813);
        diaoDuWebsocketController.broadcast(goodsSellRecord1,null);
        websocketController.broadcast(goodsSellRecord1);
        //System.out.println("now time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }*/

}
